import * as Cesium from "cesium";

// 新增广告牌
export default class addBillbroad {
  constructor(viewer) {
    this.viewer = viewer;
    this.init();
  }
  init() {
    const viewer = this.viewer;
    const list = [
      {
        position: [114.30527350657182, 30.59595484998685],
        name: "肖总",
      },
      {
        position: [114.36687292429713, 30.573724426095062],
        name: "花总",
      },
      {
        position: [114.26522916206015, 30.59026470545458],
        name: "小沈",
      },
    ];

    const entities = this.createBillboard(list);
    entities.forEach((item) => {
      viewer.entities.add(item);
    });
  }
  // 根据列表创建广告牌
  createBillboard(list) {
    const imageUrl = "/src/assets/image/position.png";
    return list.map((item) => {
      return {
        position: Cesium.Cartesian3.fromDegrees(
          item.position[0],
          item.position[1],
          0
        ),
        billboard: {
          image: imageUrl,
          color: Cesium.Color.RED,
          scale: 0.2,
        },
        label: {
          text: item.name,
          font: "20px",
          color: Cesium.Color.RED,
          pixelOffset: new Cesium.Cartesian2(0, -40),
          fillColor: Cesium.Color.BLUE,
          showBackground: false,
          backgroundColor: Cesium.Color.RED,
        },
      };
    });
  }
}
